package com.devops.jarmonitor.controller;

import com.devops.jarmonitor.service.DataSimulatorService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * 模拟控制API
 */
@RestController
@RequestMapping("/api/simulator")
@RequiredArgsConstructor
public class SimulatorController {

    private final DataSimulatorService dataSimulatorService;
    
    /**
     * 启用模拟
     */
    @PostMapping("/enable")
    public ResponseEntity<Map<String, Object>> enableSimulation() {
        dataSimulatorService.enableSimulation();
        
        Map<String, Object> response = new HashMap<>();
        response.put("success", true);
        response.put("message", "数据模拟已启用");
        response.put("status", "enabled");
        
        return ResponseEntity.ok(response);
    }
    
    /**
     * 停用模拟
     */
    @PostMapping("/disable")
    public ResponseEntity<Map<String, Object>> disableSimulation() {
        dataSimulatorService.disableSimulation();
        
        Map<String, Object> response = new HashMap<>();
        response.put("success", true);
        response.put("message", "数据模拟已停用");
        response.put("status", "disabled");
        
        return ResponseEntity.ok(response);
    }
    
    /**
     * 获取模拟状态
     */
    @GetMapping("/status")
    public ResponseEntity<Map<String, Object>> getStatus() {
        boolean enabled = dataSimulatorService.isSimulationEnabled();
        
        Map<String, Object> response = new HashMap<>();
        response.put("success", true);
        response.put("enabled", enabled);
        response.put("status", enabled ? "enabled" : "disabled");
        
        return ResponseEntity.ok(response);
    }
}
